//
//  AppDelegate+IM.m
//  GainInvest
//
//  Created by 王玉龙 on 17/3/17.
//  Copyright © 2017年 longlong. All rights reserved.
//

#import "AppDelegate+IM.h"

@implementation AppDelegate (IM)


- (void)imPushApplication:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [AuthorizationManager getIM_Authorization];
    //读取本地文件
    [self redirectNSLogToDocumentFolder];
    
//    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(connectStateChanged:) name:KNOTIFICATION_onConnected object:nil];

    [ECDevice sharedInstance].delegate = [DeviceDelegateHelper sharedInstance];
}

- (void)redirectNSLogToDocumentFolder
{
    
#if LOG_OPEN
    if(isatty(STDOUT_FILENO))
    {
        return;
    }
    
    UIDevice *device = [UIDevice currentDevice];
    if([[device model] hasSuffix:@"Simulator"])
    { //在模拟器不保存到文件中
        return;
    }
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *fileName =[NSString stringWithFormat:@"%@.log", [self.dataformater stringFromDate:[NSDate date]]];
    NSString *logFilePath = [documentsDirectory stringByAppendingPathComponent:fileName];
    freopen([logFilePath cStringUsingEncoding:NSASCIIStringEncoding],"a+",stderr);
#endif
    
}


//登录页面和主页面的切换
-(void)connectStateChanged:(NSNotification *)notification
{
    NSLog(@"notification ===== %@",notification.userInfo);
}


@end
